<template>
	<view>
		<uni-nav-bar left-icon="arrowthinleft" title="支付" :border="false" bg="bg-zhuse" color="#fff"	@clickLeft="goBack()"></uni-nav-bar>
		<view>
			<view class="bg-fff text-center padding-y-100">
				<view>
					<text class="fs-60 color-zhuse fw-bolder margin-left-10">
						<text class="fs-36">¥</text>{{info.money  || 0}}
					</text>
				</view>
			</view>
			<view class="bg-fff padding-x-30 padding-top-30 margin-top-24">
				<view class="fs-30 solid-bottom padding-bottom-30 margin-bottom-16">选择支付方式</view>
				<radio-group @change="change">
					<label  class="flex align-center justify-between padding-y-30 solid-bottom">
						<view class="flex align-center">
							<image class="ruzhu_pay_style" src="../../static/img/wx.png" mode="aspectFit">
							</image>
							<text class="fs-30 color-333">微信支付</text>
						</view>
						<radio value="wechat" checked />
					</label>
					<label class="flex align-center justify-between padding-y-30 solid-bottom">
						<view class="flex align-center">
							<image class="ruzhu_pay_style" src="../../static/img/ali.png" mode="aspectFit">
							</image>
							<text class="fs-30 color-333">支付宝支付</text>
						</view>
						<radio value="alipay" />
					</label>
					<label  class="flex align-center justify-between padding-y-30 solid-bottom">
						<view class="flex align-center">
							<image class="ruzhu_pay_style" src="../../static/img/wallet_pay.png" mode="aspectFit">
							</image>
							<text class="fs-30 color-333">余额支付</text>
						</view>
						<radio value="deposit"/>
					</label>
				</radio-group>
			</view>
			<view class="bg-fff padding-x-30 padding-top-30 margin-top-24">
				<view class="fs-30 solid-bottom padding-bottom-30 ">积分抵扣</view>
				<view  class="flex align-center justify-between padding-y-30 solid-bottom">
					<!-- <input type="number" @blur='getMoney()' v-model="points" placeholder="请输入抵扣金额"> -->
					<text class="fs-28 color-666">积分:{{points}}</text>
					<text class="fs-28 color-666">抵扣:{{points_amount}}</text>
				</view>
			</view>

			<view class="padding-60">
				<button class="public_btn" @tap="submit()">支付</button>
			</view>
		</view>

		<payPassword v-if="payShow" ref="pay" @doSubmit="doSubmit" @hide="hide"></payPassword>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				payShow: false,
				setInfo: {},
				info: {
					target: '',
					target_type: 'offline',
					// tradepwd: '',
					pay_type:'wechat',
					money:0,
					extra:[]
				},
				points:0,
				points_amount:0
			};
		},
		onLoad(opt) {
			this.info.target = opt.member_id;
			this.info.money = opt.pay_amount;
			this.points = opt.points;
			this.points_amount = opt.points_amount;
			// this.init(data)
		},
		methods: {
			// init(data){
			// 	this.$api.get_points(data).then(res => {
			// 		if (res.code == 1) {
			// 			this.have_points = res.data.have_points
			// 			this.points_max = res.data.points_max
			// 		}
			// 	})
			// },
			change(e) {
				// console.log(e);
				this.info.pay_type = e.detail.value;
			},
			submit() {
				if (this.info.pay_type == "deposit") {
					// this.payShow = true;
					this.doSubmit()
				} else {
					this.doPay();
				}
			},
			hide() {
				this.info.tradepwd = "";
				this.payShow = false;
			},
			doSubmit(data) {
				// this.info.tradepwd = data;
				this.$api.pay(this.info).then(res => {
					this.$msg(res.msg);
					if (res.code == 1) {
						setTimeout(() => {
							uni.switchTab({
								url:'/pages/my/my'
							})
						}, 300)
					}
				})
			},
			doPay() {
				this.$api.pay(this.info).then(res => {
					// this.$msg(res.msg);
					if (res.code == 1) {
						console.log(res)
						var info = res.data.payParams;
						
				
						var provider;
						if (this.info.pay_type == 'wechat') {
							provider = 'wxpay';
						} else if (this.info.pay_type == 'alipay') {
							provider = 'alipay';
						}
						uni.requestPayment({
							provider: provider,
							orderInfo: info,
							success: function(res) {
								setTimeout(() => {
									uni.switchTab({
										url:'/pages/my/my'
									})
								}, 300)
							},
							fail: function(err) {
								console.log('fail:' + JSON.stringify(err));
							}
						});
						
					}
				})

			}
		}
	};
</script>

<style lang="scss" scoped>

</style>
